/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.ws.client.program;

import junit.framework.TestCase;
import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.submit.ProgramValueBean;
import net.bioteam.appweb.user.User;
import net.bioteam.appweb.ws.WsClient;

public class EmbassyMisc extends TestCase
{

	public EmbassyMisc()
	{
		super();
	}

	public EmbassyMisc(String name)
	{
		super(name);
	}

	public WsClient client;

	protected void setUp() throws Exception
	{
		TestConfig.init();
		User user = new User();
		user.setName(TestConfig.username);
		user.setPassword(TestConfig.password);
		client = new WsClient(user, TestConfig.serviceURL, null);
	}

	public static void main(String args[]) throws Exception
	{
		EmbassyMisc test = new EmbassyMisc();
		test.setUp();
		// Method[] mss=test.getClass().getMethods();
		// for (Method ms: mss)
		// {
		// if (ms.getName().startsWith("test"))
		// {
		// ms.invoke(test);
		// //break;
		// }
		// }
		test.testTopo();
		// EmbassyMic test = new EmbassyMic("testEsim4");
		// junit.textui.TestRunner.run(test);
	}

	public void testTopo() throws Exception
	{
		String program = "topo";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		// topo -auto -signa -prol=UM -cys=cg -gly=sr -acid=dr -basic=db
		// -ohaa=da -araa=dg -sections="" -graph cps
		bean.setValue("sequence", "tsw:aqp1_human");
		bean.setValue("signature", "1");
		bean.setValue("proline", "UM");
		bean.setValue("cyssymbol", "cg");
		bean.setValue("glysymbol", "sr");
		bean.setValue("acdicaa", "dr");
		bean.setValue("basicaa", "db");
		bean.setValue("ohaa", "da");
		bean.setValue("araa", "dg");
		bean.setValue("sections", "topo.range");
		bean.setValue("_infile1", "inputs/topo.range");
		bean.setValue("graph", "cps");
		bean.setValue("outfile", "out.txt");
		bean.setValue("outseq", "seq.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);
	}

	public void testEsim4() throws Exception
	{
		String program = "esim4";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("asequence", "tembl:h45989");
		bean.setValue("bsequence", "tembl:z69719");

		bean.setValue("outfile", "out.txt");
		bean.setValue("outseq", "seq.txt");

		String[] ret = client.runProgram(bean);
		postJobProcess(ret);
	}

	protected void postJobProcess(String ret[])
	{
		String jobid = ret[0];
		TestConfig.logger.info("job id is " + jobid);
		TestConfig.logger.info("cmdline is " + ret[2]);
	}

}
